// 只能输入数字和字母
export const numLette = {
  test: /^[A-Za-z0-9]+$/,
  message: '只能输入数字和字母'
}

// 只能输入数字和字母
export const numLetteValidator = (rule, value, callback) => {
  if (numLette.test.test(value)) {
    callback()
  } else {
    callback(new Error(numLette.message))
  }
}

// 大于等于0的数字
export const greaterThan = {
  test: /^[+]{0,1}(\d+)$/,
  message: '只能输入大于0的数字'
}

// 只能输入大于0的数字
export const numGreaterThan = (rule, value, callback) => {
  if (greaterThan.test.test(value)) {
    callback()
  } else {
    callback(new Error(greaterThan.message))
  }
}

// 只能输入数字和字母和$
export const numLettes = {
  test: /^[A-Za-z0-9$]+$/,
  message: '只能输入数字和字母'
}

// 只能输入数字和字母和 $
export const numLetteValidators = (rule, value, callback) => {
  if (numLettes.test.test(value)) {
    callback()
  } else {
    callback(new Error(numLettes.message))
  }
}

// 只能输入字母和下划线
export const letterUnderLine = {
  test: /^[a-zA_]{1,}$/,
  message: '只能输入字母和下划线'
}

// 只能输入字母和下划线
export const letterUnderLineValidators = (rule, value, callback) => {
  if (letterUnderLine.test.test(value)) {
    callback()
  } else {
    callback(new Error(letterUnderLine.message))
  }
}

// 只能输入字母
export const letter = {
  test: /^[a-zA]{1,}$/,
  message: '只能输入字母'
}

// 只能输入字母
export const letterValidators = (rule, value, callback) => {
  if (letter.test.test(value)) {
    callback()
  } else {
    callback(new Error(letter.message))
  }
}

// 手机号码
export const mobile = {
  test: /^1[345789]\d{9}$/,
  message: '手机号码格式不正确'
}

// 手机号码验证器
export const mobileValidator = (rule, value, callback) => {
  if (mobile.test.test(value)) {
    callback()
  } else {
    callback(new Error(mobile.message))
  }
}

// 邮箱
export const email = {
  test: /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/,
  message: '邮箱格式不正确'
}

// 邮箱验证器
export const emailValidator = (rule, value, callback) => {
  if (email.test.test(value)) {
    callback()
  } else {
    callback(new Error(email.message))
  }
}

// 验证数字
export const number = {
  test: /^[0-9]*$/,
  message: '输入有误(请输入数字)'
}

// 数字验证器
export const numberValidator = (rule, value, callback) => {
  if (number.test.test(value)) {
    callback()
  } else {
    callback(new Error(number.message))
  }
}

// 验证器
export default {
  numLetteValidator,
  numGreaterThan,
  numLetteValidators,
  letterUnderLineValidators,
  mobileValidator,
  emailValidator,
  numberValidator
}
